<template>
    <div  class="pe-plan-content" :style="{'height':(height==null?divAutoHeight:height)+'px','width':(width==null?divAutoWidth:width)+'px', 'overflow-y':'auto'}">
        <el-collapse v-model="collapse.activeNames" @change="handleChange">
              <el-collapse-item title="" name="0">
                    <el-form
                      :inline="true"
                      :model="planData"
                      label-width="120px"
                      class="demo-ruleForm"
                    >
                      <div class="createTop" style="height:44px;">
                        <ui>
                          <li v-for="item in peBox.boxTitleData" class="createLi" :key="item.id">{{item}}</li>
                        </ui>
                      </div>
                      <div class="createTop" style="height:44px;">
                        <ui>
                          <li class="createLi">{{planData.sex}}</li>
                          <li class="createLi">
                            <input
                              type="text"
                              v-model="planData.weight"
                              @change="changeEventhandler(planData.weight,'weight')"
                            />
                          </li>
                          <li class="createLi">{{planData.allTotal}}</li>
                          <li class="createLi">
                            <input
                              type="text"
                              v-model="planData.hct"
                              @change="changeEventhandler(planData.hct,'hct')"
                            />
                          </li>
                          <li class="createLi">
                            <input
                              type="text"
                              v-model="planData.leaveBl"
                              @change="changeEventhandler(planData.leaveBl,'leaveBl')"
                            />
                          </li>
                          <li class="createLi">
                            <input
                              type="text"
                              v-model="planData.targetHct"
                              @change="changeEventhandler(planData.targetHct,'targetHct')"
                            />
                          </li>
                          <li class="createLi">
                            <input
                              type="text" readonly="readonly"
                              v-model="planData.targetLeaveEpv"
                              style="color:#303133;border:0px solid white;"
                            />
                          </li>
                          <li class="createLi">
                            <input
                              type="text"
                              v-model="planData.targetAllBl"
                              @change="changeEventhandler(planData.targetAllBl,'targetAllBl')"
                            />
                          </li>
                          <li class="createLi">
                            <input
                              type="text"
                              v-model="planData.targetXjBl"
                              @change="changeEventhandler(planData.targetXjBl,'targetXjBl')"
                            />
                          </li>
                        </ui>
                      </div>
                      <div class="createTop" style="height:300px;">
                        <div
                          class="createTopLeft"
                          style="width:49%;height:565px;border:1px solid rgba(0,0,0,0.5);float:left"
                        >
                          <el-collapse-item name="1">
                            <div
                              style="width:49%;height:228px;border:1px solid rgba(0,0,0,0.5);float:left;margin-left:2px;"
                            >
                              <div class="fontSet">目标血浆去除总量(ml):{{planData.targetLeaveBlTotal}}</div>
                              <div class="fontSet">累计公益性血浆去除量:{{planData.sumLeaveBlTotal}}</div>
                              <div class="fontSet">EPV去除比例:{{planData.epvLeaveBl}}</div>
                            </div>
                            <div
                              style="width:49%;height:228px;border:1px solid rgba(0,0,0,0.5);float:left; margin-left:5px;"
                            >
                              <div class="fontSet">单层最大出浆量(ml):{{planData.singleLayerMax}}</div>
                              <div class="fontSet">最小单层去除血浆量(ml):{{planData.singleLayerMin}}</div>
                            </div>
                          </el-collapse-item>
                          <el-collapse-item name="3">
                            <div
                              style="width:49%;height:228px;border:1px solid rgba(0,0,0,0.5);float:left;margin-left:2px;"
                            >
                              <div class="fontSet">红细胞去除总量(ml):{{planData.hxbLeaveTotal}}</div>
                              <div class="fontSet">预估红细胞去除次数:{{planData.predictHxbLeaveCount}}</div>
                            </div>
                            <div
                              style="width:49%;height:228px;border:1px solid rgba(0,0,0,0.5);float:left; margin-left:5px;"
                            >

                              <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">单层最大去除量(ml):{{planData.singleMaxLeave}}</div>
                                <!-- <input
                                  type="text"
                                  style="float:left;width:130px;height:50px;margin-top:5px;"
                                  v-model="planData.singleMaxLeave"
                                  @change="changeEventhandler(planData.singleMaxLeave,'singleMaxLeave')"
                                /> -->
                              </div>




                            </div>
                          </el-collapse-item>
                          <!-- <el-collapse-item name="6">
                            <div
                              style="width:49%;height:125px;border:1px solid rgba(0,0,0,0.5);float:left;margin-left:2px;5px;padding-bottom:5px;"
                            >
                              <div class="fontSet" style="height:62px;width:100%; padding:2px;">
                                <div style="float:left;width:200px;height:61px;">抗凝剂/全血比例:</div>
                                <input
                                  type="text"
                                  style="float:left;width:120px;height:50px;margin-top:5px;"
                                  v-model="planData.aRatioAllBlood"
                                  @change="changeEventhandler(planData.aRatioAllBlood,'aRatioAllBlood')"
                                />
                              </div>
                              <div class="fontSet" style="height:62px;width:100%;padding:2px;">
                                <div style="float:left;width:200px;height:61px;">袖带压力(mmHg):</div>
                                <input
                                  type="text"
                                  style="float:left;width:120px;height:50px;margin-top:5px;"
                                  v-model="planData.cuffPressure"
                                  @change="changeEventhandler(planData.cuffPressure,'aRatioAllBlood')"
                                />
                              </div>
                            </div>
                            <div
                              style="width:49%;height:125px;border:1px solid rgba(0,0,0,0.5);float:left; margin-left:5px;padding-bottom:5px;"
                            >
                              <div class="fontSet" style="height:62px;width:100%; padding:2px;">
                                <div style="float:left;width:200px;height:61px;">采集速度(r/min):</div>
                                <input
                                  type="text"
                                  style="float:left;width:120px;height:50px;margin-top:5px;"
                                  v-model="planData.acquisitionSpeed"
                                  @change="changeEventhandler(planData.acquisitionSpeed,'aRatioAllBlood')"
                                />
                              </div>
                              <div class="fontSet" style="height:62px;width:100%; padding:2px;">
                                <div style="float:left;width:200px;height:61px;">还输速度(r/min):</div>
                                <input
                                  type="text"
                                  style="float:left;width:120px;height:50px;margin-top:5px;"
                                  v-model="planData.voReturn"
                                  @change="changeEventhandler(planData.voReturn,'aRatioAllBlood')"
                                />
                              </div>
                            </div>
                          </el-collapse-item> -->
                        </div>
                        <div
                          class="createTopeRight"
                          style="width:48%;height:565px;border:1px solid rgba(0,0,0,0.5);float:left;margin-left:10px;margin-right:10px;"
                        >
                          <el-collapse-item name="2">
                            <div
                              style="width:49%;height:228px;border:1px solid rgba(0,0,0,0.5);float:left;margin-left:2px;"
                            >
                              <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">照射全血总量(ml):</div>
                                {{planData.shineAllBlood}}
                              </div>
                              <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">单次照射最大量(ml):</div>
                                <input
                                  type="number"
                                  min="0"
                                  max="260"
                                  style="float:left;width:130px;height:50px;margin-top:5px;"
                                  @change="changeEventhandler(planData.singShineMax,'singShineMax')"
                                  v-model="planData.singShineMax"
                                />
                              </div>
                              <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">单层照射全血量(ml):</div>
                                {{planData.singleShineAllBlood}}
                              </div>
                              <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">预估照射次数:</div>
                                {{planData.predictShineCount}}
                              </div>
                            </div>
                            <div
                              style="width:49%;height:228px;border:1px solid rgba(0,0,0,0.5);float:left; margin-left:5px;background:rgba(239,239,239);overflow-y:scroll;overflow-x:hidden;"
                            >
                              <div
                                class="table_th_title"
                                style="width:100%;height:30px;text-align:center;border:1px solid rgba(0,0,0,0.0);padding-top:5px;"
                              >
                                <div
                                  style="width:22%;height:30px;text-align:center;float:left;font-weight:bolder;background:rgba(239,239,239,0.8);margin-left:3px;"
                                >照层</div>
                                <div
                                  style="width:22%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                >红细胞量(ml)</div>
                                <div
                                  style="width:22%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                >血浆量(ml)</div>
                                <div
                                  style="width:22%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                >血浆占比</div>
                              </div>
                              <div class="table_tr_tbody" id="t_one">
                                <div class="table_tr_tbody_row" v-for="item in planData.loopCountDataR"
                                  style="margin-top:5px;width:100%;height:30px;" :key="item.id"
                                >
                                  <div
                                    style="width:22%;height:30px;text-align:center;float:left;font-weight:bolder;line-height:30px;margin-left:3px;"
                                  >{{item.indexName}}</div>
                                  <div
                                    style="width:22%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                  >
                                    <input
                                      type="text"
                                      style="height:28px;"
                                      v-model="item.hxbl"
                                      @change="changeEventhandler(item.hxbl,'hxbl')"
                                    />
                                  </div>
                                  <div
                                    style="width:22%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                  >
                                    <input
                                      type="text"
                                      style="height:28px;"
                                      v-model="item.xjl"
                                      @change="changeEventhandler(item.xjl,'xjl')"
                                    />
                                  </div>
                                  <div
                                    style="width:22%;height:30px;text-align:center;float:left;font-weight:bolder;line-height:30px;margin-left:3px;"
                                  >{{item.xjbl}}</div>
                                </div>
                              </div>
                            </div>
                          </el-collapse-item>
                          <el-collapse-item name="4">
                            <div
                              style="width:49%;height:228px;border:1px solid rgba(0,0,0,0.5);float:left;margin-left:2px;"
                            >
                              <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">采前盐水补充量(ml):</div>
                                <input
                                  type="text" readonly="readonly"
                                  style="float:left;width:130px;height:50px;margin-top:5px;border:0px solid red;color:black;"
                                  v-model="planData.preMiningBrineSupplement"
                                  @change="changeEventhandler(planData.preMiningBrineSupplement,'preMiningBrineSupplement')"
                                />
                              </div>
                              <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">通道维持量(ml/min):</div>
                                <input
                                  type="text"
                                  style="float:left;width:130px;height:50px;margin-top:5px;"
                                  v-model="planData.channelMaintenance"
                                  @change="changeEventhandler(planData.channelMaintenance,'channelMaintenance')"
                                />
                              </div>
                            <!--   <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">保压压力(mmHg):</div>
                                <input
                                  type="text"
                                  style="float:left;width:130px;height:50px;margin-top:5px;"
                                  v-model="planData.packingPressure"
                                  @change="changeEventhandler(planData.packingPressure,'packingPressure')"
                                />
                              </div> -->

                              <div class="fontSet" style="width:100%;height:57px;">
                                <div style="float:left;width:250px;height:57px;">预估盐水补充总量(ml):</div>
                                {{planData.predictMiningBrineSupplement}}
                              </div>
                            </div>
                            <div
                              style="width:49%;height:228px;border:1px solid rgba(0,0,0,0.5);float:left;  margin-left:5px;background:rgba(239,239,239);"
                            >

                              <div
                                style="width:100%;height:114px;border-bottom:1px solid rgba(0,0,0,0.5);padding-bottom:5px;text-align:center;line-height:114px;"
                              >
                                <el-button
                                  type="primary"
                                  icon="el-icon-s-claim"
                                  style="width:50%;height:64px;font-size:20px;"
                                  @click="insertPePlan"
                                >保存</el-button>
                              </div>
                              <div
                                style="width:99%;height:113px;padding-bottom:5px;text-align:center;line-height:113px;"
                              >
                                <el-button
                                  type="primary"
                                  icon="el-icon-refresh-left"
                                  style="width:50%;height:64px;font-size:20px;"
                                >重置</el-button>
                              </div>
                              <!-- <div
                                class="table_th_title"
                                style="width:100%;height:30px;text-align:center;border:1px solid rgba(0,0,0,0.0);padding-top:5px;"
                              >
                                <div
                                  style="width:25%;height:30px;text-align:center;float:left;font-weight:bolder;background:rgba(239,239,239,0.8);margin-left:3px;"
                                >照层</div>
                                <div
                                  style="width:25%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                >照射时间(s)</div>
                                <div
                                  style="width:25%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                >充氧时间(s)</div>
                              </div>
                              <div class="table_tr_tbody" id="t_two">
                                <div
                                  class="table_tr_tbody_row"
                                  v-for="item in  planData.loopCountDataT"
                                  style="margin-top:5px;width:100%;height:30px;"
                                >
                                  <div
                                    style="width:25%;height:30px;text-align:center;float:left;font-weight:bolder;line-height:30px;margin-left:3px;"
                                  >{{item.indexName}}</div>
                                  <div
                                    style="width:25%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                  >
                                    <input
                                      type="text"
                                      style="height:28px;"
                                      v-model="item.hxbl"
                                      @change="changeEventhandler(t_oneData)"
                                    />
                                  </div>
                                  <div
                                    style="width:25%;height:30px;text-align:center;float:left;font-weight:bolder;margin-left:3px;"
                                  >
                                    <input
                                      type="text"
                                      style="height:28px;"
                                      v-model="item.xjl"
                                      @change="changeEventhandler(t_oneData)"
                                    />
                                  </div>
                                  <br />
                                </div>
                              </div> -->
                            </div>
                          </el-collapse-item>
                          
                        </div>
                      </div>
                    </el-form>
              </el-collapse-item>
        </el-collapse>
    </div>
</template>
<script>
import pePlanApi from 'plugins/myaxios/interrogation/pePlan.js';
import {selectDoctorAdvice,updateDoctorAdvice,addDoctorAdvice,getDoctorAdviceProvider,selectProvider,deleteDoctorAdvice} from "plugins/axios/inquiryRecord.js"
import {mapState} from 'vuex'
export default {
    name:'pePlan',
    props:{
      hid:{
        type:[String,Number]
      },
      providerNo:{
          type:[String,Number]
      },
      height:{
        type:[String,Number]
      },
      width:{
        type:[String,Number]
      },
      data:{
        type:[Object]
      }
    },
    // props:['data','width','height','','','cVal'],
    data(){
        return{
           form:{
               planData:{},
           },
           planData: {
                id:null,
                // hid:'',
                // providerNo:'',
                sex:'',
                weight:45,
                allTotal: 3900, //全血总量
                epv: 2000, //EPV
                hct: 0.5, //HCT
                leaveBl: 0.17, //允许离体全血占比
                leaveBlTotal: 3800, //允许离体全血总量
                targetHct: 0.4, //目标HCT
                targetLeaveEpv: 0, //去除EPV比例
                targetAllBl: 0.1, //目标照射全血占比
                targetXjBl: 0.6, //目标血浆照射占比
                targetLeaveBlTotal: 0, //目标血浆去除总量
                sumLeaveBlTotal: 0, //累计工艺性血浆去除量
                epvLeaveBl: 0, //EPV去除比例
                singleLayerMax: 0, //单层最大出浆量
                singleLayerMin: 0, //最小单层去除血浆量
                hxbLeaveTotal: 0, //红细胞去除总量
                predictHxbLeaveCount: 0, //预估红细胞去除次数
                singleMaxLeave: 245, //单层最大去除量
                aRatioAllBlood: "1:16.0", //抗凝剂/全血比例
                cuffPressure: 50, //袖带压力
                acquisitionSpeed: 60, //采集速度
                voReturn: 60, //还输速度
                shineAllBlood: 0, //照射全血总量
                singShineMax: 260, //单次照射最大量
                singleShineAllBlood: 0, //单层照射全血量
                predictShineCount: 0, //预估照射次数
                loopCount: 2, //循环次数
                loopCountDataR: [
                //循环：层数/红细胞/血浆/占比 数据
                // { indexName: "1层", hxbl: 4399, xjl: 3499, xjbl: "60%" },
                // { indexName: "2层", hxbl: 4399, xjl: 3499, xjbl: "60%" }
                ],
                loopCountDataT: [
                //循环：层数/照射时间/充氧时间
                { indexName: "1层", hxbl: 4399, xjl: 3499, xjbl: "60%" },
                { indexName: "2层", hxbl: 4399, xjl: 3499, xjbl: "60%" }
                ],
                preMiningBrineSupplement: 0, //采前盐水补充量
                channelMaintenance: 5, //通道维持量
                packingPressure: 50, //保压压力
                predictMiningBrineSupplement: 0 //预估盐水补充量
           },
           peBox:{
               boxTitleData:[
                "性别",
                "体重(kg)",
                "全血总量(ml)",
                "HCT",
                "允许离体全血占比",
                "目标HCT",
                "去除EPV比例",
                "目标照射全血占比",
                "目标血浆照射占比"
               ]
           },
           collapse:{
               activeNames:['0','1','2','3','4'],
           },
           loopCountDataR:[],
        }
    },
    created(){},
    watch:{
        data(newData,oldData){
            self.planData.sex =this.data.sex==1?"男":"女";
            self.planData.weight =this.data.weight;
            self.computeAllTotal();
            self.queryPePlanData();
        },
        cVal(newData,oldData){
            let self = this;
             //全部重新计算
            self.planData.sex =this.data.sex==1?"男":"女";
            self.planData.weight =this.data.weight;
            self.computeAllTotal();
            self.queryPePlanData();
        }
    },
    computed:{
        ...mapState({clientHeight:state=>state.common.clientHeight}),
        divAutoHeight(){
            return this.clientHeight;
        },
        divAutoWidth(){
            return this.clientWidth;
        }
    },
    methods:{
        //初始化方法
      init(){
          let self = this;
          //self.planData.sex =this.data&&this.data.sex?(this.data.sex===1?'男':'女'):'男'
          self.planData.weight =this.data&&this.data.weight?this.data.weight:45
          console.log(self.providerNo)
        selectProvider(self.providerNo).then(res=>{
                if(res.content.sex==='1'){
                  self.planData.sex='男'
                }
                if(res.content.sex==='2'){
                  self.planData.sex='女'
                }
          })
          //全部重新计算
            self.computeAllTotal();
        },
        insertPePlan(){
          let self = this;
          self.planData.providerNo = self.providerNo;
          self.loopCountDataR = (self.planData.loopCountDataR==null||self.planData.loopCountDataR==undefined)?[]:self.planData.loopCountDataR;       
          pePlanApi.insertPePlan(self.planData).then(res=>{
              self.insertLoopCountDataR(res.content.id);
              self.queryPePlanData();
          });
        },
        insertLoopCountDataR(tid){
          let self = this;
          let data=[];
          self.loopCountDataR.forEach(element => {    
                    element.tid = tid;
                    data.push(element);       
          });
          if(data!=null&&data.length>0){
            pePlanApi.insertLoopCountDataR(data).then(res=>{
            });
          }
        },
        queryPePlanData(){
          let self = this;
          pePlanApi.queryPePlanData(self.hid,self.providerNo).then(res=>{
              self.$emit('sendDataToParent', res.content);
              // let contentData = res.content;
              // if(res.content!=null && res.content!=undefined && res.content.length>0){
              //     let tid = contentData[contentData.length-1].id;
              //     self.insertLoopCountDataR(tid);
              // }
          });
        },
        //处理数据
        handleChange(val) {
            console.log(val);
        },
        changeEventhandler(val, type) {
          
            let self = this;

            //全部重新计算
            self.computeAllTotal();

            // switch (type) {
            //     case "weight":
            //       self.computeAllTotal();
            //     break; //修改页面【体重】,重新计算【全血总量】
            //     case "hct":
            //        //修改页面【HCT】值，重新计算【单层最大出浆量】
            //       self.computeSingleLayerMax();
            //       // //修改页面【HCT】值，重新计算【红细胞去除总量】
            //       self.computeHxbLeaveTotal();
            //       self.computePredictHxbLeaveCount();
            //     break;
            //     case "targetHct":
            //       // //修改页面【目标HCT】值，重新计算【红细胞去除总量】
            //       self.computeHxbLeaveTotal();
            //       self.computePredictHxbLeaveCount();
            //     break;
            //     case "singleMaxLeave":
            //       // self.validateSingleMaxLeave();//验证输入的值，是否在 0 - 250 区间
            //       // //修改页面【单层最大去除量】值，重新计算【预估红细胞去除次数】
            //       //  predictHxbLeaveCount: 2, //预估红细胞去除次数
            //       self.computePredictHxbLeaveCount();
            //     break;

            //     case "leaveBl":
            //     self.computeLeaveBlTotal();
            //     break; //修改页面【允许离体全血占比】，重新计算【允许离体全血量】
            //     case "targetLeaveEpv":
            //     self.computeTargetLeaveBlTotal();
            //     break; //修改页面【去除EPV比例】,  重新计算【目标血浆去除总量】
            //     case "targetAllBl":
            //       self.computeShineAllBlood();
            //       self.computeHxbLeaveTotal(); //同步更新【计算红细胞去除总量】值
            //       self.computePredictHxbLeaveCount();//计算【预估红细胞去除次数】
            //       self.computeSingleLayerMax();//重新计算【单层最大出浆量】
            //       self.computePreMiningBrineSupplement();//计算【采前盐水补充量】
            //       self.computeSumLeaveBlTotal();
            //     break; //修改页面【目标照射全血占比】,  重新计算【照射全血总量】
            //     case "targetXjBl":
            //       self.computeLoopCountDataR();
            //       self.computeHxbLeaveTotal(); //同步更新【计算红细胞去除总量】值
            //       self.computePredictHxbLeaveCount();//计算【预估红细胞去除次数】
            //       self.computeSingleLayerMax();//重新计算【单层最大出浆量】
            //       self.computePreMiningBrineSupplement();//计算【采前盐水补充量】
            //       self.computeSumLeaveBlTotal();
            //     break; //修改页面【目标血浆照射占比】,  重新计算【每层照射数据】
            //     case "singShineMax":
            //       self.computePredictShineCount();
            //       self.computeHxbLeaveTotal(); //同步更新【计算红细胞去除总量】值
            //       self.computePredictHxbLeaveCount();//计算【预估红细胞去除次数】
            //       self.computeSingleLayerMax();//重新计算【单层最大出浆量】
            //       self.computePreMiningBrineSupplement();//计算【采前盐水补充量】
            //       self.computeSumLeaveBlTotal();
            //     break; //修改页面【单次照射最大量】,  重新计算【预估照射次数】
            //     default:
            //     break;
            // }
        },
        /**
         * 计算 sumLeaveBlTotal: 0, //累计公益性血浆去除量
         * 
         */
        computeSumLeaveBlTotal(){
            let self = this;
            //先清空
            self.planData.sumLeaveBlTotal = 0;
            //累计公益性血浆去除量，首先加上第一层去除的
            self.planData.sumLeaveBlTotal += self.planData.singleLayerMin;
            if(self.planData.loopCountDataR.length > 1){
                

                let lastHxbzl = Math.ceil(self.planData.allTotal * self.planData.hct);//上一层的红细胞量，这里等于初始红细胞量：初始的全血总量 * 初始的HCT
                let lastHct = 0;//上一层的HCT

                for(let idx = 1;idx < self.planData.loopCountDataR.length;idx++){
                  
                  if(idx == 1){
                    //获取上一层的红细胞量
                    //重新计算第一层完后的HCT：第一层红细胞量 / (初始全血总量 + 采前盐水补充量)
                    let newHct = (lastHxbzl / (self.planData.allTotal + self.planData.preMiningBrineSupplement)).toFixed(4);
                    //计算第二层的最大出浆量
                    let secondSingleLayerMax = Math.ceil(275 * (0.85 / newHct - 1));
                    //计算第二层最小单层去除血浆量
                    let secondSingleLayerMin = secondSingleLayerMax - self.planData.loopCountDataR[idx].xjl;
                    if(secondSingleLayerMin < 0){
                      secondSingleLayerMin = 0;
                    }
                    //累计公益性血浆去除量，首先加上第一层去除的
                    self.planData.sumLeaveBlTotal += secondSingleLayerMin;

                    lastHct = newHct;
                  }else{
                    //第三层及以后

                    //获取上一层的红细胞量
                    lastHxbzl = Math.ceil(self.planData.allTotal * lastHct);

                    //当层红细胞去除量
                    let currentHxbqcl = 0;
                    if(self.planData.predictHxbLeaveCount >= idx){
                      currentHxbqcl = self.planData.hxbLeaveTotal - (self.planData.singleMaxLeave * idx);
                      if(currentHxbqcl > self.planData.singleMaxLeave){
                        currentHxbqcl = self.planData.singleMaxLeave;
                      }
                    }

                    //重新计算HCT : (上一层红细胞总量 - 当层红细胞去除总量) / 上层全血总量  暂时用（全血总量 + 采前盐水补充量）
                    lastHct = ((lastHxbzl - currentHxbqcl) / (self.planData.allTotal + self.planData.preMiningBrineSupplement)).toFixed(4);

                    //计算当前层的最大出浆量
                    let currentSingleLayerMax = Math.ceil(275 * (0.85 / lastHct - 1));
                    //计算当前层最小单层去除血浆量
                    let currentSingleLayerMin = currentSingleLayerMax - self.planData.loopCountDataR[idx].xjl;
                    if(currentSingleLayerMin < 0){
                      currentSingleLayerMin = 0;
                    }
                    //累计公益性血浆去除量
                    self.planData.sumLeaveBlTotal += currentSingleLayerMin;

                  }

                }



            }else{
              //只有一层，把首层加上就行了
            }

            //计算epv去除比例： 累计公益性血浆去除量 / EPV
            self.planData.epvLeaveBl = (self.planData.sumLeaveBlTotal / self.planData.epv).toFixed(2);
            self.planData.targetLeaveEpv = self.planData.epvLeaveBl;
            //进行【目标血浆去除总量】计算
            self.computeTargetLeaveBlTotal();

            //【预估盐水补充总量】计算 ： 采前盐水补充量 + 红细胞去除总量 + 累计公益性血浆去除量
            self.planData.predictMiningBrineSupplement = self.planData.preMiningBrineSupplement + self.planData.hxbLeaveTotal + self.planData.sumLeaveBlTotal;

        },


        /**
         * 计算 sumLeaveBlTotal: 0, //累计公益性血浆去除量
         * 
         */
        // computeSumLeaveBlTotal_() {
        //   let self = this;

        //   //累计公益性血浆去除量
        //   self.planData.sumLeaveBlTotal += self.planData.singleLayerMin;

        //   //第二层
        //   //第一层红细胞总量 = 最开始的【全血总量】 * 最开始的HCT
        //   let firstHxbzl = Math.ceil(self.planData.allTotal * self.planData.hct);
        //   //重新计算第一层完后的HCT
        //   let newHct = (firstHxbzl / (self.planData.allTotal + self.planData.preMiningBrineSupplement)).toFixed(4);
        //   alert("第二层的HCT:"+newHct);


        //   //计算第二层的最大出浆量
        //   let secondSingleLayerMax = Math.ceil(275 * (0.85 / newHct - 1));
        //   // alert("第二层的最大出浆量:"+secondSingleLayerMax);
        //   //计算第二层最小单层去除血浆量
        //   //这里展示的【最小单层去除血浆量】 = 【单层最大出浆量】 - 【第一层照射的血浆量】  
        //   let secondSingleLayerMin = 0;
        //   if(self.planData.loopCountDataR.length > 0){
        //       secondSingleLayerMin = secondSingleLayerMax - self.planData.loopCountDataR[1].xjl;
        //   }
        //   // alert("第二层的最小单层去除血浆量:"+secondSingleLayerMin);
        //   //累加上一层最小单层去除血浆量
        //   //累计公益性血浆去除量
        //   self.planData.sumLeaveBlTotal += secondSingleLayerMin;

        //   // alert("第二层后的累计公益性血浆去除量："+self.planData.sumLeaveBlTotal);


        //   //计算第三层的 HCT = 上一层的红细胞总量 - 当层红细胞去除量 / 上层全血总量

        //   let thirdHxbqcl = 0;//第三层红细胞去除量
        //   if(self.planData.predictHxbLeaveCount > 2){
        //     thirdHxbqcl = self.planData.hxbLeaveTotal - (self.planData.singleMaxLeave * 2);
        //     if(thirdHxbqcl > self.planData.singleMaxLeave){
        //       thirdHxbqcl = self.planData.singleMaxLeave;
        //     }
        //   }


        //   //上一层的全血总量，暂时用（全血总量 + 采前盐水补充量）
        //   let secondAllTotal = self.planData.allTotal + self.planData.preMiningBrineSupplement;
        //   // alert("第二层全血总量："+secondAllTotal);
        //   //第二层的红细胞总量
        //   // let secondHxbzl = Math.ceil(self.planData.allTotal * newHct);
        //   let secondHxbzl = Math.ceil(secondAllTotal * newHct);
          
        //   let thirdHct = ((secondHxbzl - thirdHxbqcl) / secondAllTotal).toFixed(4);
        //   alert("第三层HCT  ："+thirdHct);

        //   //计算第三层的最大出浆量
        //   let thirdSingleLayerMax = Math.ceil(275 * (0.85 / thirdHct - 1));

        //   //计算第三层最小单层去除血浆量
        //   //这里展示的【最小单层去除血浆量】 = 【单层最大出浆量】 - 【第一层照射的血浆量】  
        //   let thirdSingleLayerMin = 0;
        //   if(self.planData.loopCountDataR.length > 0){
        //       thirdSingleLayerMin = thirdSingleLayerMax - self.planData.loopCountDataR[1].xjl;
        //   }
        //   //累计公益性血浆去除量
        //   self.planData.sumLeaveBlTotal += thirdSingleLayerMin;



        // },

        /**
         * 计算 preMiningBrineSupplement: 0, //采前盐水补充量
         * 
         */
        computePreMiningBrineSupplement() {
          
            let self = this;
            //第一层红细胞总量 = 最开始的【全血总量】 * 最开始的HCT
            let firstHxbzl = Math.ceil(self.planData.allTotal * self.planData.hct);
            //允许离体的全血总量 = 【允许离体全血占比】 * 【全血总量】
            let xyltqxzl = Math.ceil(self.planData.leaveBl * self.planData.allTotal);
            //第一层实际离体全血总量 = 杯容量275 + 管容量45 + 第一层血浆去除量(最小单层去除血浆量) + 第一层照射全血量
            let firstRealLtqxzl = 275 + 45 + self.planData.singleLayerMin + self.planData.singleShineAllBlood;
            // 差值 = (第一层实际离体全血总量 - 允许离体的全血总量) 
            //采前盐水补充量 = 差值 > 0 ? 差值 : 0
            let ltqxlCz = firstRealLtqxzl - xyltqxzl;
            self.planData.preMiningBrineSupplement = ltqxlCz > 0 ? ltqxlCz : 0;
        },


        /**
         * 验证输入的【单层最大去除量】，是否在 0 - 250 区间
         */
        validateSingleMaxLeave() {
            let self = this;
            if(self.planData.singleMaxLeave < 0 || self.planData.singleMaxLeave > 250){
                self.$message.error("【单层最大去除量】的值必须在 0 - 250 之间...");
                if(self.planData.singleMaxLeave < 0 ){
                    self.planData.singleMaxLeave = 0;
                }else{
                    self.planData.singleMaxLeave = 250;
                }
            }
        },

        /**
         * 计算 预估红细胞去除次数 predictHxbLeaveCount
         * 预估红细胞去除次数 = 红细胞去除总量 hxbLeaveTotal / 单层最大去除量 singleMaxLeave
         */
        computePredictHxbLeaveCount() {

            let self = this;
            if(self.planData.hxbLeaveTotal > 0 && self.planData.singleMaxLeave > 0){
                self.planData.predictHxbLeaveCount = Math.ceil(self.planData.hxbLeaveTotal / self.planData.singleMaxLeave);
            }else{
              self.planData.predictHxbLeaveCount = 0;
            }
            
            
        },
        /**
         * 计算红细胞去除总量 hxbLeaveTotal: 390, //
         * 红细胞去除总量 = (HCT - 目标HCT) * 全血总量
         */
        computeHxbLeaveTotal() {
            // hct: 0.5, //HCT
            // targetHct: 0.4, //目标HCT
            // allTotal ,//全血总量
            let self = this;
            if(self.planData.allTotal > 0 && self.planData.hct > 0 && self.planData.targetHct > 0){
                self.planData.hxbLeaveTotal = Math.ceil((self.planData.hct - self.planData.targetHct) * self.planData.allTotal);
            }

            self.computePredictHxbLeaveCount();//同步更新【预估红细胞去除次数】值
            
            
        },
        //计算全血总量
        computeAllTotal() {
            let self = this;
            self.planData.allTotal = Math.ceil(self.planData.weight * 0.065 * 1000);
            self.computeEpv(); //同步更新【Epv】值
            self.computeLeaveBlTotal(); //同步更新【允许离体全血】值
            self.computeShineAllBlood(); //同步更新【照射全血总量】值 
            self.computeHxbLeaveTotal(); //同步更新【计算红细胞去除总量】值
            self.computePredictHxbLeaveCount();//计算【预估红细胞去除次数】
            self.computeSingleLayerMax();//重新计算【单层最大出浆量】
            self.computePreMiningBrineSupplement();//计算【采前盐水补充量】
            self.computeSumLeaveBlTotal();//测试

        },
        //单层最大出浆量
        computeSingleLayerMax() {
            let self = this;
            self.planData.singleLayerMax = Math.ceil(275 * (0.85 / self.planData.hct - 1));
            //这里展示的【最小单层去除血浆量】 = 【单层最大出浆量】 - 【第一层照射的血浆量】  
            if(self.planData.loopCountDataR.length > 0){
                self.planData.singleLayerMin = self.planData.singleLayerMax - self.planData.loopCountDataR[0].xjl;
                if(self.planData.singleLayerMin < 0){
                  self.planData.singleLayerMin = 0;
                }
            }
        },
        //计算EPV
        computeEpv() {
            let self = this;
            if (self.planData.sex === "男") {
                self.planData.epv = Math.ceil((1 - self.planData.hct) * (1530 + 41 * self.planData.weight));
            } else if (self.planData.sex === "女") {
                self.planData.epv = Math.ceil((1 - self.planData.hct) * (864 + 47.2 * self.planData.weight));
            }
            
        },
        //进行【允许离体全血】计算
        computeLeaveBlTotal() {
            let self = this;
            self.planData.leaveBlTotal =
            self.planData.leaveBl * self.planData.allTotal;
        //待关联计算实际离体全血量
        },
        //进行【目标血浆去除总量】计算
        computeTargetLeaveBlTotal() {
            let self = this;
            self.planData.targetLeaveBlTotal = Math.ceil(self.planData.targetLeaveEpv * self.planData.epv);
        },
        //进行【照射全血总量】计算
        computeShineAllBlood() {
          
            let self = this;
            self.planData.shineAllBlood = Math.ceil(self.planData.targetAllBl * self.planData.allTotal);
            self.computePredictShineCount();
        },
        //进行【每层照射数据】计算
        computeLoopCountDataR() {
            let self = this;
            

            //清空数组
            self.planData.loopCountDataR.splice(0,self.planData.loopCountDataR.length); 

            /**
             *  singleShineAllBlood: 260, //单层照射全血量
                predictShineCount: 2, //预估照射次数
                targetXjBl: 0.6, //目标血浆照射占比
                shineAllBlood //照射全血总量
             * 
             *  loopCountDataR: [
                //循环：层数/红细胞/血浆/占比 数据
                { indexName: "1层", hxbl: 4399, xjl: 3499, xjbl: "60%" },
                { indexName: "2层", hxbl: 4399, xjl: 3499, xjbl: "60%" }
                ]
             */
            let exitLastAllBlood = 0;//除开最后一层之前的那几层的【单层照射全血量】和，最后一层用【照射全血总量】减去这个和，得到最后一层的【单层照射全血量】
            let xjbl_ = (self.planData.targetXjBl * 100 ) + "%";
            
            for(let i = 1; i<=self.planData.predictShineCount ; i++){
              if(i < self.planData.predictShineCount){
                exitLastAllBlood += self.planData.singleShineAllBlood;
                let xjCount = Math.ceil(self.planData.singleShineAllBlood * self.planData.targetXjBl);//单层照射血浆量
                let hxbCount = self.planData.singleShineAllBlood - xjCount;//单层照射红细胞量

                let singleData_ = {
                  indexName: i+"层",
                  hxbl: hxbCount,
                  xjl: xjCount,
                  xjbl: xjbl_
                };
                self.planData.loopCountDataR[i-1] = singleData_;
              }else{
                let lastBlood = self.planData.shineAllBlood - exitLastAllBlood;
                let xjCount = Math.ceil(lastBlood * self.planData.targetXjBl);//单层照射血浆量
                let hxbCount = lastBlood- xjCount;//单层照射红细胞量
                let singleData_ = {
                  indexName: i+"层",
                  hxbl: hxbCount,
                  xjl: xjCount,
                  xjbl: xjbl_
                };
                self.planData.loopCountDataR[i-1] = singleData_;
              }
                
            }

            //计算singleLayerMin: 10, //最小单层去除血浆量
            //这里展示的【最小单层去除血浆量】 = 【单层最大出浆量】 - 【第一层照射的血浆量】  
            if(self.planData.loopCountDataR.length > 0){
                self.planData.singleLayerMin = self.planData.singleLayerMax - self.planData.loopCountDataR[0].xjl;
            }
            if(self.planData.singleLayerMin < 0){
              self.planData.singleLayerMin = 0;
            }
            

        },
        //计算预估照射次数
        computePredictShineCount() {
            let self = this;
            self.planData.predictShineCount = Math.ceil( self.planData.shineAllBlood / self.planData.singShineMax );
            self.planData.loopCount = self.planData.predictShineCount;
            self.computeSingleShineAllBlood();
        },
        //计算单层照射全血量
        computeSingleShineAllBlood() {
            let self = this;
            self.planData.singleShineAllBlood = Math.ceil(self.planData.shineAllBlood / self.planData.predictShineCount);
            self.computeLoopCountDataR();
        },   
    },
}
</script>

<style scoped>
.pePlanContent{
    background:red;    
}
.createTop {
    width: 90%;
    height: 100%;
    margin: 0 auto;
}
.fontcolors {
    color: red;
} 
.createLi {
    display: inline;
    line-height: 40px;
    width: 10.61%;
    float: left;
    border: 1px solid rgba(0, 0, 0, 0.5);
    text-align: center;
    font-size: 20px;
    font-weight: bolder;
    padding: 1px;
}
.fontSet {
    width: 100%;
    height: 76px;
    text-align: center;
    line-height: 76px;
    font-size: 20px;
    font-weight: bolder;
}
ul{
    list-style: none;
}
input {
    width: 99%;
    height: 39px;
    border: 1px solid rgba(0, 0, 0, 0.5);
    text-align: center;
    line-height: 40px;
    font-size: 20px;
    font-weight: bolder;
    background: white;
    color: red;
}
</style>